<?php

namespace App\Http\Middleware;

use Closure;
use App\model\Operation;

class Rbac
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        
		$rbac=$request->session()->get('rbac');
		if(!$rbac){
		return redirect('/rbac');
		}
		$url=$request->getRequestUri();
		$arr=explode("?",$url);

        if(!in_array($arr[0],$rbac)){
		 
		  return redirect('/rbac');
		}

        $ip=$request->getClientIp();
	    $use_id=$request->session()->get('use_name');
		$model=new Operation();
		$arr=$model->pageWork($ip,$use_id,$arr[0]);
		return $next($request);
    }
}
